import request from '@/config/axios'

export interface FileUploadVO {
  category?: string
  file: any
  isPrivate?: boolean
}

export interface FileUploadPresignedUrlVO {
  category?: string
  fileName: string
  mimeType: string
  size: number
  isPrivate?: boolean
}

export interface FileCreateVO {
  serialNo: string
}

export const uploadFile = async (data: FileUploadVO) => {
  return await request.upload({
    url: '/infra/file/upload',
    data: data,
    extension: {
      ignoreRepeatCheck: true
    }
  })
}

export const getFileUploadPresignedUrl = async (data: FileUploadPresignedUrlVO) => {
  return await request.post({ url: '/infra/file/upload-presigned-url', data: data })
}

export const createFile = async (data: FileCreateVO) => {
  return await request.post({
    url: '/infra/file/create',
    data: data,
    extension: { errorSilent: true }
  })
}

export const getFilePage = async (params: PageParam) => {
  return await request.get({ url: '/infra/file/page', params })
}

export const deleteFile = async (id: number) => {
  return await request.delete({ url: '/infra/file/delete', params: { id } })
}
